package com.example.javafx01;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.io.IOException;

public class HelloApplication extends Application {
    @Override
    public void start(Stage stage) throws IOException {
        // 创建布局容器
        StackPane root = new StackPane();

        Button bt = new Button("Click me");
        // 可以设置按钮的首选大小
        bt.setPrefSize(100, 30);

        bt.setOnAction(e -> {
            Stage stage1 = new Stage();
            stage1.setHeight(300);
            stage1.setWidth(300);

            // 为新窗口的按钮也添加布局容器
            StackPane secondaryRoot = new StackPane();
            Button secondBt = new Button("Click me");
            secondBt.setPrefSize(100, 30); // 设置按钮大小
            secondaryRoot.getChildren().add(secondBt);
            secondBt.setOnAction(e1 -> {
                stage1.close();
            });
            stage1.setScene(new Scene(secondaryRoot));
            stage1.show();
        });

        // 将按钮添加到布局容器
        root.getChildren().add(bt);

        // 使用布局容器作为场景的根节点
        Scene scene = new Scene(root, 500, 500);
        stage.setScene(scene);
        stage.setHeight(600);
        stage.setWidth(600);
        stage.setTitle("Hello!");
        // 注意：建议使用相对路径而非绝对路径加载资源
        stage.getIcons().add(new Image("file:C:/Users/skyjay/IdeaProjects/JavaFx01/resource/images/lifeAfter.jpg"));
        stage.setResizable(false);

        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}